<template>
    <CommonModal v-model:show="modalShow" :title="modalTitle" @onSubmit="onSubmit" style="width: 600px">
        <n-form
        ref="modalFormRef"
        :model="modalForm"
        :inline="false"
        :rules="rules">
      <n-grid :cols="24" :x-gap="24">
        <n-form-item-gi :span="24" label="guild-id" path="guildId" hidden>
          <n-input v-model:value="modalForm.type" default-value="MJ" clearable placeholder="请选择类型"/>
        </n-form-item-gi>
        <n-form-item-gi :span="24" label="资源名称" path="resourceName">
          <n-input v-model:value="modalForm.resourceName" clearable placeholder="请输入资源名称"/>
        </n-form-item-gi>
        <n-form-item-gi :span="24" label="是否公开" path="isPublic">
          <n-select :options="isPublicOption" v-model:value="modalForm.isPublic">
          </n-select>
        </n-form-item-gi>
        <n-form-item-gi :span="24" label="guild-id" path="guildId">
          <n-input v-model:value="modalForm.guildId" clearable placeholder="请输入guild-id"/>
        </n-form-item-gi>

        <n-form-item-gi :span="24" label="channel-id" path="channelId">
          <n-input v-model:value="modalForm.channelId" clearable placeholder="请输入channel-id"/>
        </n-form-item-gi>
        <n-form-item-gi :span="24" label="user-token" path="userToken">
          <n-input v-model:value="modalForm.userToken" clearable placeholder="请输入user-token"/>
        </n-form-item-gi>

<!--        <n-form-item-gi :span="24" label="session-id" path="sessionId">-->
<!--          <n-input v-model:value="modalForm.sessionId"  clearable placeholder="请输入session-id"/>-->
<!--        </n-form-item-gi>-->
<!--        <n-form-item-gi :span="24" label="user-agent" path="userAgent">-->
<!--          <n-input v-model:value="modalForm.userAgent"  placeholder="请输入user-agent"/>-->
<!--        </n-form-item-gi>-->

        <n-form-item-gi :span="12" label="默认资源" path="isDefault">
          <n-radio-group
              v-model:value="modalForm.isDefault"
              name="left-size"
              style="margin-bottom: 12px"
              default-value="0"
          >
            <n-radio-button value="1">
              是
            </n-radio-button>
            <n-radio-button value="0">
              否
            </n-radio-button>
          </n-radio-group>
        </n-form-item-gi>


        <n-form-item-gi :span="12" label="是否启用代理" path="proxyEnable">
          <n-radio-group
              v-model:value="modalForm.proxyEnable"
              name="left-size"
              style="margin-bottom: 12px"
              default-value="0"
          >
            <n-radio-button value="1">
              是
            </n-radio-button>
            <n-radio-button value="0">
              否
            </n-radio-button>
          </n-radio-group>
        </n-form-item-gi>
        <n-form-item-gi v-if="modalForm.proxyEnable === '1'" :span="12" label="代理IP" path="proxyIp">
          <n-input v-model:value="modalForm.proxyIp" clearable placeholder="请输入代理IP"/>
        </n-form-item-gi>
        <n-form-item-gi v-if="modalForm.proxyEnable === '1'" :span="12" label="代理端口" path="proxyPort">
          <n-input v-model:value="modalForm.proxyPort" clearable placeholder="请输入代理端口"/>
        </n-form-item-gi>

        <n-form-item-gi :span="8" label="并发数" path="coreSize">
          <n-input-number v-model:value="modalForm.coreSize" placeholder="请输入并发数"/>
        </n-form-item-gi>
        <n-form-item-gi :span="8" label="队列长度" path="queueSize">
          <n-input-number v-model:value="modalForm.queueSize"   placeholder="请输入队列长度"/>
        </n-form-item-gi>
        <n-form-item-gi :span="8" label="超时时间" path="timeoutMinutes">
          <n-input-number v-model:value="modalForm.timeoutMinutes"  placeholder="请输入超时时间">
            <template #suffix>
              分钟
            </template>
          </n-input-number>
        </n-form-item-gi>



      </n-grid>
    </n-form>
    </CommonModal>
</template>

<script lang="ts">
import {defineComponent} from "vue";
import CommonModal from "@/components/commonModal/index.vue"
import {useCommonModal} from "@/components/commonModal/useCommonModal"
import { resourceController } from "@/api/resource/resourceController.api"
import {isPublicOption} from '@/views/resource'
export default defineComponent({
    name: "UserEditForm",
    components: {
        CommonModal,isPublicOption
    },
    setup() {
        const {
            modalShow,
            modalTitle,
            modalForm,
            modalFormRef,
            modalLoading,
            onAdd,
            onEdit,
            onSubmit,
            onDeleteById,
            onDeleteByIds
        } = useCommonModal("midjourney", {
                needSsl: false,
                isAuth: "0",
                type: "MJ",
                coreSize : 3,
                queueSize : 50,
                timeoutMinutes : 10
            },
            resourceController.addSDResource,
            resourceController.updateResource,resourceController.deleteResource,resourceController.deleteBatch
        )



        const rules = {
            resourceName: {type: "string", required: true, message: "请填写资源名称", trigger: ['blur', 'change']},
            guildId: {type: "string", required: true, message: "请填写guildId", trigger: ['blur', 'change']},
            channelId: {type: "string", required: true, message: "请填写channelId", trigger: ['blur', 'change']},
            userToken: {type: "string", required: true, message: "请填写userToken", trigger: ['blur', 'change']},
            // sessionId: {type: "string", required: true, message: "请填写sessionId", trigger: ['blur', 'change']},
            // userAgent: {type: "string", required: true, message: "请填写userAgent", trigger: ['blur', 'change']},
            coreSize: {type: "number", required: true, message: "请填写并发数", trigger: ['blur', 'change']},
            queueSize: {type: "number", required: true, message: "请填写队列长度", trigger: ['blur', 'change']},
            timeoutMinutes: {type: "number", required: true, message: "请填写超时时间", trigger: ['blur', 'change']}
        }

        return {
            modalShow,
            modalTitle,
            modalForm,
            modalFormRef,
            modalLoading,
            rules,
            isPublicOption,
            onAdd,
            onEdit,
            onSubmit,
            onDeleteById,
            onDeleteByIds
        }
    }
})
</script>

<style scoped>

</style>
